/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;
import DTO.usuarioDTO;
import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;
/**
 *
 * @author User
 */
public class ModuloAdmiListarUsuarios extends javax.swing.JFrame {

    usuarioDTO user;
    /**
     * Creates new form ModuloAdmiListarUsuarios
     */
    public ModuloAdmiListarUsuarios(usuarioDTO user) {
        this.user = user;
        initComponents();
        this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        cmbEstadoListar = new javax.swing.JComboBox();
        btnBuscarListar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTListar = new javax.swing.JTable();
        btnVolver = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGE/logo.JPG"))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Century Gothic", 1, 18)); // NOI18N
        jLabel1.setText("LISTAR USUARIOS");

        jLabel3.setFont(new java.awt.Font("Century Gothic", 0, 12)); // NOI18N
        jLabel3.setText(" ESTADO DE USUARIO :");

        cmbEstadoListar.setFont(new java.awt.Font("Century Gothic", 0, 12)); // NOI18N
        cmbEstadoListar.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ACTIVO", "INACTIVO" }));

        btnBuscarListar.setFont(new java.awt.Font("Century Gothic", 0, 12)); // NOI18N
        btnBuscarListar.setText("BUSCAR");
        btnBuscarListar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarListarActionPerformed(evt);
            }
        });

        jTListar.setFont(new java.awt.Font("Century Gothic", 0, 12)); // NOI18N
        jTListar.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "RUT", "NOMBRE", "APELLIDO PATERNO", "APELLIDO MATERNO", "FECHA NACIMIENTO", "SEXO", "TEL. PARTICULAR", "TEL. TRABAJO", "TEL. MOVIL", "FAX", "EMAIL", "PERFIL", "USUARIO", "CONTRASEÑA"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jTListar.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jTListar.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(jTListar);

        btnVolver.setFont(new java.awt.Font("Century Gothic", 0, 12)); // NOI18N
        btnVolver.setText("VOLVER");
        btnVolver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVolverActionPerformed(evt);
            }
        });

        jLabel4.setText("MENÚ ADMINISTRADOR\\LISTAR USUARIOS");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(jLabel2)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(122, 122, 122)
                                .addComponent(jLabel1))
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel4))))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3)
                        .addGap(35, 35, 35)
                        .addComponent(cmbEstadoListar, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnBuscarListar))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 827, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(372, 372, 372)
                        .addComponent(btnVolver)))
                .addContainerGap(37, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4))
                        .addGap(29, 29, 29)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(cmbEstadoListar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnBuscarListar))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnVolver)
                .addGap(16, 16, 16))
        );

        setSize(new java.awt.Dimension(908, 490));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void btnBuscarListarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarListarActionPerformed
        ArrayList<usuarioDTO> salida = LOGIN.Administrador.ListarUsuarios(cmbEstadoListar.getSelectedItem().toString());
        if (salida.isEmpty()) {
            javax.swing.JOptionPane.showMessageDialog(null, "No se encontraron Usuarios");
        }
        else
        {
            DefaultTableModel modelo =(DefaultTableModel)this.jTListar.getModel();
            modelo.setNumRows(0);
            for (usuarioDTO u : salida) {
                Object[] arreglo = {u.getRut_usua(), u.getNombre_usua(), u.getApell_paterno_usua(), 
                u.getApell_materno_usua(), u.getFech_nac_usua(), u.getSexo_usua(), u.getTel_part_usua(), 
                u.getTel_trab_usua(), u.getTel_mov_usua(), u.getFax_usua_int(), u.getE_mail_usua(), 
                u.getPerfil().getNom_perfil(), u.getUsuario_usua(), u.getContrasena_usua()};
                modelo.addRow(arreglo);
            }
        }
    }//GEN-LAST:event_btnBuscarListarActionPerformed

    private void btnVolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVolverActionPerformed
        MenuAdministrador admi = new MenuAdministrador(user);
        admi.setVisible(true);
        ModuloAdmiListarUsuarios.this.dispose();
    }//GEN-LAST:event_btnVolverActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscarListar;
    private javax.swing.JButton btnVolver;
    private javax.swing.JComboBox cmbEstadoListar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTListar;
    // End of variables declaration//GEN-END:variables
}
